package com.tengju.data.domain.model.brand;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

@Getter
@AllArgsConstructor
public enum BrandAnalysisSortType {

    SALE_MONEY_ASC("sale_money","asc","销售额升序","sale_money asc"),
    SALE_MONEY_DESC("sale_money","desc","销售额降序","sale_money desc"),

    DEALER_TURNOVER_ASC("dealer_turnover","asc","会员成交人数升序","dealer_turnover asc"),
    DEALER_TURNOVER_DESC("dealer_turnover","desc","会员成交人数降序","dealer_turnover desc"),

    DEALER_TURNOVER_ACTIVE_ASC("dealer_turnover_active","asc","会员成交活跃度升序","dealer_turnover_active asc"),
    DEALER_TURNOVER_ACTIVE_DESC("dealer_turnover_active","desc","会员成交活跃度降序","dealer_turnover_active desc"),

    ;


    String sortColumn;
    String sortType;
    String desc;
    String sql;


    public static BrandAnalysisSortType fromSortColumnAndType(String sortColumn,String sortType) {

        //默认销售额降序
        if (StringUtils.isEmpty(sortColumn) || StringUtils.isEmpty(sortType)) {
            return BrandAnalysisSortType.SALE_MONEY_DESC;
        }

        for (BrandAnalysisSortType type : values()) {
            if (type.sortColumn.equals(sortColumn) && type.sortType.equals(sortType)) {
                return type;
            }
        }
        return BrandAnalysisSortType.SALE_MONEY_DESC;
    }
}
